import {cloneDeep, filter} from "lodash-es";

export function useFilter(columnsRef, setLoading) {
    const filterArr = ref([])

    watch(
        () => unref(columnsRef),
        (newVal) => {
            setFilterChange(newVal);
        }
    );

    const setFilterChange = (columnsRef:any[]) => {
        if (!columnsRef.length) return;
        const columns = cloneDeep(columnsRef)
        console.log(columns);
        let arr = []
        columns.map(item => {
            if (item.filter  && !!item.filterOptionValue) {
                arr.push({
                    key: item.key,
                    filterOptionValue: item.filterOptionValue,
                    type: item.filterType
                })
            }
        })
        filterArr.value = arr
        console.log(filterArr.value);
    }

    const getFilterChange = computed(() => {
        return cloneDeep(filterArr.value)
    })

    return {
        getFilterChange
    };
}
